package indi.lqzhi.basic.ui.basic.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.blankj.utilcode.util.ArrayUtils;
import com.blankj.utilcode.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: Teimlz
 * @ClassName: ViewPage2FragmentStatusAdapter
 * @Date: 2021-09-23 16-22
 * @Description: This is a ViewPage2FragmentStatusAdapter Class.
 * @Version: V1.0
 */
public class ViewPage2FragmentStatusAdapter extends FragmentStateAdapter {

    private List<Fragment> fragments;

    public ViewPage2FragmentStatusAdapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
        fragments = new ArrayList<>();
    }

    public ViewPage2FragmentStatusAdapter(@NonNull FragmentActivity fragmentActivity, Fragment []fragments) {
        super(fragmentActivity);
        this.fragments = ArrayUtils.isEmpty(fragments) ? new ArrayList<>() : Arrays.asList(fragments);
    }

    public ViewPage2FragmentStatusAdapter(@NonNull FragmentActivity fragmentActivity,List<Fragment> fragments) {
        super(fragmentActivity);
        this.fragments = CollectionUtils.isNotEmpty(fragments) ? fragments : new ArrayList<>();
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragments.get(position);
    }

    @Override
    public int getItemCount() {
        return fragments.size();
    }
}
